%%
%x1=read image you want to process
%radius=depend on the hole density
y1=zeros(size(x1)); %matrix for classification
value_at_90th_percentile=zeros(size(x1));
value_at_10th_percentile=zeros(size(x1));
ratio=zeros(size(x1));
for i=1:size(x1,1)
    for j=1:size(x1,2)
        k=circrop([j,i],radius,x1);
        sorted_k = sort(k);
        value_at_90th_percentile(i,j) = mean(sorted_k(round(0.9 * length(k)):end));
        value_at_10th_percentile(i,j) = mean(sorted_k(1:round(0.1 * length(k))));
        ratio(i,j)=(value_at_90th_percentile(i,j)- value_at_10th_percentile(i,j))/(max(x1,[],"all")-min(x1,[],"all"));      
        if ratio(i,j)>0.28
              y1(i,j)=1; %solid region
        end
    end
end
figure;imshow(y1)
%% function to crop a circle at a point
function k=circrop(x,r,im)
    k=[];
  for i=-r:r
     for j=-r:r
         if round(x(1)+j)>0&&round(x(1)+j)<size(im,2)&&round(x(2)+i)>0&&round(x(2)+i)<size(im,1)&&sqrt(i^2+j^2)<=r
             k=[k;im(round(x(2)+i),round(x(1)+j))];
         end
     end
  end
end